#include "messageAdministrator.hpp"

void MessageAdministrator::turnRight(int metros){
   /*char valor[5];
    if (metros == 0){
        message = "Doble a la derecha";
    }else{
        sprintf_s(valor,5,"%d",metros);
        std::string aux(valor);*/
        //message = "A " + aux + " metros doble a la derecha";
        message = "Doble a la derecha en la proxima esquina";
}

void MessageAdministrator::turnLeft(int metros){
    /*char valor[5];
    if (metros == 0){
        message = "Doble a la izquierda";
    }else{
        sprintf_s(valor,5,"%d",metros);
        std::string aux(valor);*/
        //message = "A " + aux + " metros doble a la izquierda";
        message = "Doble a la izquierda en la proxima esquina";
}

void MessageAdministrator::follow(int metros){
    /*char valor[5];
    sprintf_s(valor,5,"%d",metros);
    std::string aux(valor);*/
    //message = "Continue por " + aux + " metros.";
    message = "Continue derecho por la calle que esta transitando actualmente";
}

void MessageAdministrator::arrive(int metros){
    /*char valor[5];
    sprintf_s(valor,5,"%d",metros);
    std::string aux(valor);*/
    //message = "Llegando al destino a " + aux + " metros";
    message = "Llegando al destino";
}

void MessageAdministrator::arriveRight(){
    message = "Llegando al destino por la derecha";
}
void MessageAdministrator::arriveLeft(){
    message = "Llegando al destino por la izquierda";
}

void MessageAdministrator::cleanMessage(){
    this->message = "";
}

MessageAdministrator::MessageAdministrator(){
    this->create();
}

void MessageAdministrator::create(){
	this->message= "";
}

void MessageAdministrator::updateNextAction(int xPosition, int yPosition, BifurcationOption direction, int nextX, int nextY, int nextNextX, int nextNextY, int numParam/*, int longStreet*/){
    int metros = 0;
    
    if (direction == DEATH){
        message = "HA COLISIONADO.";
        return;
    }
    /*if (direction == UP){
         metros = yPosition - nextY;
    } else{
         if (direction == DOWN){
              metros = nextY - yPosition;
         }else {
              if (direction == LEFT){
                  metros = xPosition - nextX;
              } else{
                  metros = nextX - xPosition;
              }
         }
    }*/
    //metros = (metros < 0)? -metros: metros;
        if ((nextX == nextNextX && (direction == UP || direction == DOWN)) ||
            (nextY == nextNextY && (direction == LEFT || direction == RIGHT))){
                this->follow(metros);
        } else{
            if (nextX == nextNextX && ((direction == RIGHT && nextNextY < yPosition) || (direction == LEFT && nextNextY > yPosition)) ||
                (nextY == nextNextY && ((direction == UP && nextX > nextNextX)||(direction == DOWN && nextX < nextNextX)) )){
                    this->turnLeft(metros);
            }
            else{
                if (nextX == nextNextX &&((direction == RIGHT && nextNextY > yPosition) || (direction == LEFT && nextNextY < yPosition)) ||
                    (nextY == nextNextY && ((direction == UP && nextX < nextNextX) || (direction == DOWN && nextX > nextNextX)))){
                    this->turnRight(metros);
                   }
            }
        }
		if (numParam==1){
            this->arrive(metros); 
		}
		if (numParam==3)
		{
			 this->cleanMessage();
		}
}

std::string MessageAdministrator::getMessage(){
    return this->message;
}